import { InjectRepository } from '@nestjs/typeorm';
import { User } from '../database/user/user.entity';
import { Repository } from 'typeorm';
import { Inject } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { Request } from 'express';

export class UserRepository {
    constructor(
        @InjectRepository(User)
        private userRepository: Repository<User>,
        @InjectRepository(User, 'mysql2')
        private userRepository1: Repository<User>,
        @Inject(REQUEST) private request: Request,
    ) {}
    getRepository(): Repository<User> {
        console.log(this.request);
        const { query } = this.request;
        if (query.db == 'mysql2') {
            return this.userRepository1;
        }
        return this.userRepository;
    }
}
